echo "Hello, World!"
echo "${API_SERVER_IP}"
echo "${K8E_TOKEN}"
echo "${K8E_URL}"

# journalctl -u k8e.service --lines 100 -f
export cilium_version=$(
	curl -sL \
		https://api.github.com/repos/cilium/cilium-cli/releases/latest |
		jq -r '.tag_name '
)

echo "cilium_version: ${cilium_version}"

/var/lib/k8e/data/current/bin/cilium
wget https://ghproxy.net/github.com/cilium/cilium-cli/releases/download/${cilium_version}/cilium-linux-amd64.tar.gz
tar zxvf cilium-linux-amd64.tar.gz
chmod +x cilium
rm -rf /var/lib/k8e/data/current/bin/cilium
cp cilium /var/lib/k8e/data/current/bin
cilium install --list-versions

export k8e_version=$(
	curl -sL \
		https://api.github.com/repos/xiaods/k8e/releases/latest |
		jq -r '.tag_name '
)

echo "k8e_version: ${k8e_version}"
wget https://ghproxy.net/github.com/xiaods/k8e/releases/download/${k8e_version}/k8e
chmod +x k8e
rm -rf /usr/local/bin/k8e
cp k8e /usr/local/bin

# 安装nvida插件 支持gpu
kubectl create -f https://ghproxy.net/https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/main/deployments/static/nvidia-device-plugin.yml

# 不要以root用户安装 可以安装最新版版本驱动
paru -S libnvidia-container-tools libnvidia-container-bin
paru -Syyu --needed linux-headers lsb-release intel-ucode nvidia-beta cuda --noconfirm

# 修改运行时
cd /var/lib/k8e/agent/etc/containerd
cp config.toml config.toml.tmpl

#将nvida 设置为默认
[plugins."io.containerd.grpc.v1.cri".containerd]
snapshotter = "overlayfs"
disable_snapshot_annotations = true
default_runtime_name = "nvidia"

#wasmedge 设置为默认
[plugins."io.containerd.grpc.v1.cri".containerd]
snapshotter = "overlayfs"
disable_snapshot_annotations = true
default_runtime_name = "wasmedge"
